<template>
  <div class="expricing result">
    <span class="formTitle">
      <i class="vertical-bar"></i>定价子任务结果
    </span>
    <div class="expricingForm" style="border:solid 1px #ccc;">
      <el-form
        :model="searchForm"
        ref="searchRef"
        label-width="150px"
        style="margin-top:10px"
        label-position="right"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="任务名称: " prop="taskName">
              <el-input v-model="searchForm.taskName" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="定价编号: " prop="pricingCode">
              <el-input v-model="searchForm.pricingRecord.pricingCode" readonly></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="头寸表数据: " prop="positionTable">
              <el-input v-model="searchForm.positionTable" readonly></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="数据日期：" prop="dataDate">
              <el-date-picker
                v-model="searchForm.pricingRecord.dataDate"
                type="date"
                style="width:100%"
                value-format="yyyy-MM-dd"
                readonly
                placeholder
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="定价情景: " prop="positions">
              <el-input v-model="searchForm.scene.sceneName" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="情景版本: " prop="positions">
              <el-input v-model="searchForm.scene.versionNum" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="定价结果：" prop="status">
              <el-select v-model="searchForm.status" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in statusOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="账号：" prop="accountNum">
              <el-input v-model="searchForm.accountNum" maxlength="32"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="机构：" prop="orgCode">
              <div class="treeBoxBig">
                <div class="treeBox">{{ searchForm.org }}</div>
                <div class="treeBtnCS" @click="treeBtnorg"></div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="科目: " prop="subjectCode">
              <div class="treeBoxBig">
                <div class="treeBox">{{ searchForm.subject }}</div>
                <div class="treeBtnCS" @click="treeBtnsubject"></div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="币种：" prop="currencyCode">
              <el-select v-model="searchForm.currencyCode" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in currencyOption"
                  :key="item.currencyId"
                  :label="item.currencyName"
                  :value="item.currencyId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="产品：" prop="productCode">
              <div class="treeBoxBig">
                <div class="treeBox">{{ searchForm.product }}</div>
                <div class="treeBtnCS" @click="treeBtnproduct"></div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="行业：" prop="industryCode">
              <div class="treeBoxBig">
                <div class="treeBox">{{ searchForm.industry }}</div>
                <div class="treeBtnCS" @click="treeBtnindustry"></div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="起息日：" prop="orgDate">
              <el-date-picker
                v-model="searchForm.orgDate"
                type="date"
                style="width:100%"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="原始期限：" prop="orgTerm">
              <!-- <el-form-item label="指定期限：" prop="assignTerm"> -->
              <el-col :span="10">
                <el-input v-model.trim="searchForm.orgTermL" maxlength="40"></el-input>
              </el-col>
              <el-col :span="14">
                <el-select v-model="searchForm.orgTermdate" placeholder="请选择" style="width:100%">
                  <el-option
                    v-for="item in dateOption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="利率类型：" prop="rateTypeCd">
              <el-select v-model="searchForm.rateTypeCd" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in rateTypeCdOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="支付类型：" prop="payTypeCd">
              <el-select v-model="searchForm.payTypeCd" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in payTypeCdOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="重定价频率：" prop="repriceFreq">
              <el-col :span="10">
                <el-input v-model.trim="searchForm.repriceFreqL" maxlength="40"></el-input>
              </el-col>
              <el-col :span="14">
                <el-select v-model="searchForm.rpricFreqMult" placeholder="请选择" style="width:100%">
                  <el-option
                    v-for="item in dateOption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="container" style="text-align:center">
          <el-col style="margin-bottom:10px;" class="content-left">
            <el-button @click="searchFunc()">查询</el-button>
            <el-button @click="reset()">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="expricingTable">
      <el-row class="container">
        <el-col style="margin:10px 0px 10px 0px" class="content-left">
          <el-button @click="exportExPricingResult()">执行详情</el-button>
          <el-button @click="goBack()">返回</el-button>
        </el-col>
      </el-row>
      <el-table
        ref="multipleModelTable"
        :data="tableModelData"
        style="width: 100%"
        @row-click="authorizeModelFor"
      >
        <el-table-column width="55" type="selection" ></el-table-column>
        <el-table-column prop="acctNo" label="账号" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dataDt" label="数据日期" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="orgCdDisp" label="机构" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="prdCdDisp" label="产品" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="sbjtCdDisp" label="科目" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="ccyCdDisp" label="币种" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="curBal" label="当前余额" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="startDt" label="起息日" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="execRate" label="对客利率" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="transRate" label="基础转移价格" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="finalTransRate" label="最终转移价格" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="compstPricAdjst" label="组合定价调整项" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="transIe" label="转移收支" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="bcRuleRes" label="BreakCharge结果" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="bfRuleRes" label="BreakFunding结果" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="accumGalY" label="年度累计损益" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="accumGal" label="累计损益" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="hisBalAccum" label="历史余额累计" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="startExecRate" label="起息日的执行利率" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="startBaseFtp" label="起息日的基础转移价格" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="startFinaFtp" label="起息日的最终转移价格" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="lastRpricExecRate" label="上次重定价日执行利率" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="lastRpricBaseFtp" label="上次重定价日基础价格" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="lastRpricFinaFtp" label="上次重定价日最终价格" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="rpricFinaFtp" label="上次重定价余额" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="origAmt" label="原始余额" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="matuDt" label="到期日" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="term" label="原始期限" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="rpricDtAdjstTp" label="重定价类型代码" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="lastRepricDt" label="上次重定价日期" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="nextRepricDt" label="下次重定价日期" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="repricFreq" label="重定价频率" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="pmtTpDisp" label="支付类型" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="lastPrinPmtDt" label="上次支付日" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="nextPrinPmtDt" label="下次支付日" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchForm.page"
        :page-size="searchForm.size"
        @refresh="searchFunc"
        :total="total"
      ></pagination>
    </div>
    <!-- 树选择框的弹框 -->
    <el-dialog
      v-dialogDrag
      title="选择值"
      :visible.sync="showMemberTree"
      append-to-body
      width="55%"
      top="2%"
      @close="cancel"
    >
      <!-- 引入 -->

      <relation-tree
        ref="relationTree"
        :indexItems="indexItems"
        :itemData="itemData"
        :dictCode="dictCode"
        @selectDataFunc="selectDataFunc"
      ></relation-tree>
      <!-- :mulSelect="mulSelect" -->
    </el-dialog>
    <!-- 树选择框的弹框 结束-->
  </div>
</template>
<script>
import { pricingTask, expricing } from "@/api/index";
import { getDict } from "@/api/getDict";
import { publicManage_pub } from "@/api/index";
import relationTree from "@/components/params/relationTree";

export default {
  props: {
    blockId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      //任务名称
      taskName: "异常定价",
      //头寸数据表
      positions: "FTP_PD_RESULT_EXCEPTION",
      product: "",
      org: "",
      industry: "",
      subject: "",
      //选择值组件所需信息
      showMemberTree: false,
      dictCode: "OrganUnit",
      indexItems: 0,
      itemData: [],
      resetSearchFrom: {
        taskName: "异常定价",
        positionTable: "FTP_PD_RESULT_EXCEPTION",
        pricingRecord: {},
        scene: {},
        page: 1,
        size: 15
      },
      searchForm: {
        taskName: "异常定价",
        positionTable: "FTP_PD_RESULT_EXCEPTION",
        pricingRecord: {},
        scene: {},
        page: 1,
        size: 15
      },
      //币种
      currencyOption: [],
      //年月日
      dateOption: [],
      //头寸数据表
      positionOptions: [],
      //定价状态
      statusOption: [],
      //支付类型
      payTypeCdOption: [],
      //利率类型
      rateTypeCdOption: [],
      tableModelData: [],
      total: null
    };
  },
  watch: {},
  components: {
    relationTree
  },
  created() {
    this.detailInit();
    this.getDict("ftp_pricing_status");
    this.getDict("ftp_cp_rate_type_cd");
    this.getDict("ftp_cp_pay_type_cd");
    this.getDict("ftp_cp_time_type");
    this.getDict("ftp_pricing_task_status");
    // this.findPositionTableList();
    this.queryDimCurrency();
    this.findPositionTableList();
  },
  computed: {},
  mounted() {},
  methods: {
    //异常定价初始化方法
    detailInit() {
      let data = {
        blockId: this.blockId
      };
      expricing.toBlockDetail(data).then(res => {
        if ((res.code = 200)) {
          //存一份到重置数据中
          this.searchForm.pricingRecord = res.data.block;
          this.searchForm.scene = res.data.scene;
          this.resetSearchFrom.pricingRecord = res.data.block;
          this.resetSearchFrom.scene = res.data.scene;
          this.searchFunc();
        } else {
          return this.$message.error(res.message);
        }
      });
    },
    //返回异常首页
    goBack() {
      this.$emit("closeExMonitor");
    },
    reset() {
      //深拷贝数据
      this.searchForm = this.$clone(this.resetSearchFrom);
    },
    searchFunc() {
      expricing.checkCurrentOrganPrivilege().then(result => {
        //有权限查看数据
        if (result.code == 200) {
          console.log(this.searchForm, "怎么根绝他不调用这个方法？ ");
          let data = {
            dataDt: this.searchForm.pricingRecord.dataDate,
            acctNo: this.searchForm.accountNum,
            ccyCd: this.searchForm.currencyCode,
            industryCd: this.searchForm.industryCd,
            orgCd: this.searchForm.industryCd,
            startDt: this.searchForm.orgCd,
            term: this.searchForm.orgTermL,
            termMult: this.searchForm.orgTermdate,
            pmtTp: this.searchForm.payTypeCd,
            positionTableFix: this.searchForm.pdName,
            pricStat: this.searchForm.status,
            prdCd: this.searchForm.prdCd,
            rateTp: this.searchForm.rateTypeCd,
            rpricFreq: this.searchForm.repriceFreqL,
            rpricFreqMult: this.searchForm.rpricFreqMult,
            sbjtCd: this.searchForm.sbjtCd,
            page: this.searchForm.page,
            size: this.searchForm.size
          };
          console.log(data, "传递的数据");
          expricing.findAllExResult(data).then(res => {
            if (res.code == 200) {
              console.log(res, "findall查出来的数===========");
              this.tableModelData = res.data.rows;
            } else {
              this.$message.error("查询失败");
            }
          });
        } else {
          this.$message.warning(result.message);
        }
      });
    },
    queryDimCurrency() {
      let data = {
        currencyCode: "",
        currencyDescribe: "",
        currencyFlag: "",
        currencyName: "",
        currencySign: "",
        order: "",
        orderBy: "",
        page: 0,
        size: 0,
        status: ""
      };
      console.log(data, "data");
      publicManage_pub.currencyManageQuery(data).then(res => {
        if (res.code == 200) {
          this.currencyOption = res.data;
          console.log(res, "chadaodeshujv===========");
        } else {
          this.$message.error(res.message);
        }
      });
    },
    findPositionTableList() {
      pricingTask.findPositionTableList().then(res => {
        if (res.code == 200) {
          this.positionOptions = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    getDict(data) {
      getDict(data).then(res => {
        if (res.code == 200) {
          if (data == "ftp_pricing_status") {
            this.statusOption = res.datas;
          } else if (data == "ftp_cp_rate_type_cd") {
            this.rateTypeCdOption = res.datas;
          } else if (data == "ftp_cp_pay_type_cd") {
            this.payTypeCdOption = res.datas;
          } else if (data == "ftp_cp_time_type") {
            this.dateOption = res.datas;
          } else if (data == "ftp_pricing_task_status") {
            this.statusOption = res.datas;
          }
        } else {
          this.$message.error(res.message);
        }
      });
    },
    treeBtnorg() {
      this.dictCode = "OrganUnit";
      this.treeBtn();
    },
    treeBtnsubject() {
      this.dictCode = "GeneralLedger";
      this.treeBtn();
    },
    treeBtnproduct() {
      this.dictCode = "Product";
      this.treeBtn();
    },
    treeBtnindustry() {
      this.dictCode = "Industry";
      this.treeBtn();
    },
    cancel() {
      this.showMemberTree = false;
    },
    selectDataFunc(val) {
      this.showMemberTree = false;
      if (val) {
        let params = val;
        console.log(params, "params");
        console.log(params.row, "params.row[0]");

        if (this.dictCode == "GeneralLedger") {
          this.searchForm.subject = params.row.dictItemName;
          this.searchForm.sbjtCd = params.row.dictItemCode;
        } else if (this.dictCode == "OrganUnit") {
          this.searchForm.org = params.row.dictItemName;
          this.searchForm.orgCd = params.row.dictItemCode;
        } else if (this.dictCode == "Product") {
          this.searchForm.product = params.row.dictItemName;
          this.searchForm.prdCd = params.row.dictItemCode;
        } else {
          this.searchForm.industry = params.row.dictItemName;
          this.searchForm.industryCd = params.row.dictItemCode;
        }
      }
    },
    treeBtn() {
      this.showMemberTree = true;
      
    },
    //点击行选中
    authorizeModelFor(row) {
      if (this.$refs.multipleModelTable) {
        this.$refs.multipleModelTable.clearSelection();
      }
      this.$refs.multipleModelTable.toggleRowSelection(row, true);
    },
    handleSizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
      console.log(val, "每页数");
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
      console.log(val, "当前页");
    },
    //执行详情
    exportExPricingResult() {
      this.$emit("toExEngineTask", this.searchForm.pricingRecord.pricingCode);
    }
  }
};
</script>

<style lang="scss" scoped>
.treeBoxBig {
  // width: 320px;
  width: 100%;
  height: 32px;
  border: 1px solid #ababab;
  border-radius: 4px;
  .treeBox {
    width: 100%;
    height: 32px;
    padding-left: 10px;
    line-height: 32px;
  }
  .treeBtnCS {
    background: url("~@/assets/images/popWindow_arrow.gif");
    background-repeat: no-repeat;
    height: 32px;
    width: 32px;
    position: absolute;
    // left: 296px;
    right: 0;
    top: 8px;
    cursor: pointer;
  }
}
</style>
<style lang="scss" scoped>
.dialogSearchBox {
  header {
    text-align: center;
    span {
      margin: 0 20px;
    }
  }
}
.selectBox {
  background: url("~@/assets/images/popWindow_arrow.gif");
  background-repeat: no-repeat;
  height: 26px;
  width: 23px;
  position: absolute;
  right: 0;
  top: 5px;
  cursor: pointer;
}

.formTitle {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 10px;
}
</style>
